﻿#region 命名空间

using System;
using Microsoft.Practices.Unity;
using Microsoft.Practices.Unity.InterceptionExtension;

#endregion

namespace Sharp.Infrastructure.Crosscutting
{
    /// <summary>
    ///     移除缓存
    /// </summary>
    [AttributeUsage(AttributeTargets.Method)]
    public class CacheRemoveAttribute : HandlerAttribute
    {
        /// <summary>
        ///     移除缓存
        /// </summary>
        public CacheRemoveAttribute()
        {
        }

        /// <summary>
        ///     移除缓存
        /// </summary>
        /// <param name="key"></param>
        public CacheRemoveAttribute(string key)
        {
            Key = key;
        }

        /// <summary>
        ///     缓存Id
        /// </summary>
        public string Key { get; set; }


        public override ICallHandler CreateHandler(IUnityContainer container)
        {
            //创建具体Call Handler，并调用
            CacheRemoveHandler handler = new CacheRemoveHandler(Key)
            {
                Order = Order
            };
            return handler;
        }
    }
}